<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            position: fixed;
            border: 1px solid;
            right: 0;
            bottom: 50px;
            display: none;
        }
    </style>
</head>
<body>
    <button>点击</button>
    <div>回到顶部</div>
    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    <script>
        console.log(window.innerWidth);
        console.log(window.innerHeight);

        console.log(document.documentElement.clientWidth);
         console.log(document.documentElement.clientHeight);
        
        //  包含滚动条的高度
         console.log(document.body.clientWidth);
        console.log(document.body.clientHeight);

        document.querySelector('button').onclick=function(){
            // 元素距离顶部的距离
            console.log(this.offsetTop);
             console.log(this.offsetLeft);
            
        }

        document.querySelector('div').onclick = function(){
           
            // 滚动条的位置
            console.log(window.scrollY);
            console.log(window.scrollX);
            // 设置滚动条的位置
             window.scrollTo(0,10)
            
        }

        window.onscroll =function(){
            console.log(window.scrollY);
            if (window.scrollY>=300) {

                 document.querySelector('div').style.display = 'block'
            }else{
                  document.querySelector('div').style.display = 'none'
            }
            
        }
         
        
    </script>
</body>
</html>